#ifndef UPLOAD_FILE_H
#define UPLOAD_FILE_H

#include <QtNetwork>
#include <QHostAddress>
#include <QMessageBox>
#include <QDataStream>
#include <QByteArray>
#include <QDebug>
#include <QDateTime>
#include <QFile>
#include <QFileDialog>


class upload_file : public QObject {
Q_OBJECT

public:
    explicit upload_file(QObject *parent = nullptr);

    /**
     * @brief Upload 上传文件主函数
     * @param path
     */
    void Upload(QString path);

    void setUsername(const QString &newUsername);

signals:

    /**
     * @brief finish 完成传输
     */
    void finish();

    void socket_disconnect();

private slots:

private:
    /**
     * @brief sendfileData 发送文件数据
     */
    void sendfileData();

    QTcpSocket *file_socket;

    QTimer *timer;

    QFile file; // 文件对象
    QString filename; // 文件名

    qint64 total_bytes = 0; //文件总字节数
    qint64 bytes_send = 0; //已发送的字节数

    bool is_connected = false;

    QString username;
};

#endif // UPLOAD_FILE_H
